﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;


using LMD.Constant;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for EventTable
    /// </summary>
    public class EventTable : CacheAbstraction
    {
        public DataTable GetEventTable()
        {
            return GetEventTable(false);
        }
        public DataTable GetEventTable(bool bForceRefresh)
        {
            String sxCacheKey = KCache.P_EVENT;

            if(bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                String sxQuery = "select P_EVENT_ID, CODE from P_EVENT";

                DataTable dt = dbl.GetDataTable(sxQuery);

                AddToCache(sxCacheKey, dt, CacheType.Daily);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }

        public String GetEventName(int iEventId)
        {
            String sxReturn = String.Empty;
            String sxWhere = "P_EVENT_ID = " + iEventId.ToString();
            DataTable dtResult = GetEventTable();
            DataRow[] drResult = dtResult.Select(sxWhere);

            if (drResult.Length > 0)
                sxReturn = Convert.ToString(drResult[0]["CODE"]);

            return sxReturn;
        }

        public override String GetCacheFilename()
        {
            return KCache.Filename.PARAMETER_TABLE;
        }
    }
}